package com.cmic.rcs.emoji.controller.web;

import com.cmic.rcs.emoji.entity.dto.EnterpriseMemberRequest;
import com.cmic.rcs.emoji.entity.dto.PageRequest;
import com.cmic.rcs.emoji.entity.vo.EnterpriseMemberVo;
import com.cmic.rcs.emoji.entity.vo.PageResult;
import com.cmic.rcs.emoji.service.EnterpriseMemberService;
import com.cmic.rcs.enhance.message.g5.core.common.Response;
import com.cmic.rcs.enhance.message.g5.core.common.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 企业成员管理接口
 */
@RestController
@RequestMapping("/api/web/enterprises/{enterpriseCode}/members")
@Slf4j
public class EnterpriseMemberController {
    @Autowired
    private EnterpriseMemberService enterpriseMemberService;

    /**
     * 获取企业成员列表
     */
    @PostMapping("/list")
    public Response listMembers(@PathVariable("enterpriseCode") String enterpriseCode,
                                @RequestBody PageRequest pageRequest) {
        log.info("获取企业成员列表，企业编码：{}，分页参数：{}", enterpriseCode, pageRequest);
        PageResult<EnterpriseMemberVo> result = enterpriseMemberService.listMembers(enterpriseCode, pageRequest);
        return ResponseData.OK(result);
    }

    /**
     * 添加企业成员
     */
    @PostMapping("/add")
    public Response addMember(@PathVariable("enterpriseCode") String enterpriseCode,
                              @RequestBody EnterpriseMemberRequest request) {
        log.info("添加企业成员，企业编码：{}，成员信息：{}", enterpriseCode, request.getPhoneNumber());
        enterpriseMemberService.addMember(enterpriseCode, request);
        return ResponseData.OK();
    }

    /**
     * 删除企业成员
     */
    @PostMapping("/delete/{id}")
    public Response deleteMember(@PathVariable("id") Long memberId) {
        log.info("删除企业成员，成员ID：{}", memberId);
        enterpriseMemberService.deleteMember(memberId);
        return ResponseData.OK();
    }
}
